﻿<?php
require_once(dirname(dirname(__FILE__)).'/config.php'); 
require_once(dirname(dirname(__FILE__)).'/include/class_com_sql.php'); // a mysql class.
class isa_join_people
{
	private $_name = "";
	private $_number = "";
	private $_class = "";
	private $_telphone = "";
	private $_email = "";
	private $_ip = "";
	
	function __construct($name, $number, $class, $telphone, $email, $ip)
	{
       $this->setName($name);
	   $this->setNumber($number);
	   $this->setClass($class);
	   $this->setTelphone($telphone);
	   $this->setEmail($email);
	   $this->setIP($ip);
	}
	
	function __destruct()
	{
	}
	
	function Submit()
	{
		$db = new cSql();
		$db->con(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
		$sql = $this->getInsert();
		$result = $db->query($sql);
		return $result;
	}
	
	function CheckbyName()
	{
		$db = new cSql();
		$db->con(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
		$sql = $this->getbyName($this->_name);
		$result = $db->query($sql);
		if($result && $result->num_rows > 0) 
			return true;
		return false;
	}
	
	function CheckbyNumber()
	{
		$db = new cSql();
		$db->con(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
		$sql = $this->getbyNumber($this->_number);
		$result = $db->query($sql);
		if($result && $result->num_rows > 0) 
			return true;
		return false;
	}
	
	function CheckRepeat()
	{
		$db = new cSql();
		$db->con(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
		$sql = $this->getRepeat($this->_number, $this->_email);
		$result = $db->query($sql);
		if($result && $result->num_rows > 0) 
			return true;
		return false;
	}
	
	function GetJoin()
	{
		$db = new cSql();
		$db->con(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
		$sql = $this->getList();
		$result = $db->query($sql);
		return $result;
	}
	
	function setName($name)
	{
		$this->_name = $this->Format($name);
	}
	
	function setNumber($number)
	{
		$this->_number = $this->Format($number);
	}

	function setClass($class)
	{
		$this->_class = $this->Format($class);
	}

	function setTelphone($telphone)
	{
		$this->_telphone = $this->Format($telphone);
	}

	function setEmail($email)
	{
		$this->_email = $this->Format($email);
	}

	function setIP($ip)
	{
		$this->_ip = $this->Format($ip);
	}

	protected function Format($value)
	{
		$value = htmlspecialchars($value, ENT_QUOTES);
		$value = addslashes($value);
		return $value;
	}
	
	protected function getList()
	{
		$sql = "select * from `isa_web_join`";
		return $sql;
	}

	protected function getInsert()
	{
		$sql = "INSERT INTO `isa_web_join`(`join_name`, `join_number`, `join_class`, `join_tel`, `join_mail`, `join_date`, `join_ip`) VALUES (";
		$sql = $sql . "'" . $this->_name . "', '" . $this->_number;
		$sql = $sql . "', '" . $this->_class . "', '" . $this->_telphone . "', '" . $this->_email ."', now(), '" . $this->_ip . "' )";
		return $sql;
	}
	
	protected function getbyName($name)
	{
		$sql = "select * from `isa_web_join` where `join_name` = '" . $name . "' limit 1";
		return $sql;
	}
	
	protected function getbyNumber($number)
	{
		$sql = "select * from `isa_web_join`  where `join_number` = '" . $number . "' limit 1";
		return $sql;
	}

	protected function getRepeat($number, $email)
	{
		if($number != "")
			$sql = "select * from `isa_web_join`  where `join_number` = '" . $number . "' or `join_mail` = '" . $email . "' limit 1";
		else
			$sql = "select * from `isa_web_join`  where `join_mail` = '" . $email . "' limit 1";
		return $sql;
	}
}
?>